package com.lanmei.group.weixin.controller.admin;

import java.util.Date;

import org.apache.shiro.authz.annotation.RequiresRoles;

import com.jfinal.aop.Clear;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;
import com.lanmei.group.weixin.interceptor.ManagerInterceptor;
import com.lanmei.group.weixin.model.SiteInfo;
import com.lanmei.group.weixin.utils.ShiroUtil;
@Clear(ManagerInterceptor.class)
@RequiresRoles(value = {"admin" })
public class SiteInfoController extends Controller{
	
	public void list(){
		Page<SiteInfo> page = new SiteInfo().paginat(1, 10);
		setAttr("page", page);
		render("list.jsp");
	}
	public void toAdd(){
		render("add.jsp");
	}
	public void add(){
		SiteInfo siteInfo = getModel(SiteInfo.class,"site");
		siteInfo.setCreateTime(new Date());
		siteInfo.setCreateUser(ShiroUtil.getLoginName());
		siteInfo.save();
		this.redirect("/admin/site/list");
	}
	public void toEdit(){
		int siteId = getParaToInt("siteId");
		SiteInfo siteInfo = new SiteInfo().dao.findById(siteId);
		setAttr("siteInfo", siteInfo);
		render("edit.jsp");
	}
	public void update(){
		SiteInfo siteInfo = getModel(SiteInfo.class,"site");
		siteInfo.setUpdateTime(new Date());
		siteInfo.setUpdateUser(ShiroUtil.getLoginName());
		siteInfo.update();
		this.redirect("/admin/site/list");
	}
	public void delete(){
		int siteId = getParaToInt("siteId");
		SiteInfo siteInfo = new SiteInfo().dao.findById(siteId);
		siteInfo.delete();
		this.redirect("/admin/site/list");
	}

}
